﻿using System;
using System.Collections.Generic;

namespace JSH.ITDiplom.OOPC01.PersonalIdentityNumber.BusinessLayer
{
    /// <summary>
    /// Gender constants
    /// </summary>
    public enum Gender
    {
        Male, Female, Unknown
    }

    /// <summary>
    /// Abstract Personal identity number class
    /// </summary>
    public abstract class PersonalIdentityNumber
    {
        protected IPersonalIdentityNumberValidation[] validations;
        protected readonly string personalIdentityNumber;

        protected PersonalIdentityNumber(string personalIdentityNumber)
        {
            this.personalIdentityNumber = personalIdentityNumber;
        }

        /// <summary>
        /// Birthday property
        /// </summary>
        public DateTime? BirthDay { get; protected set; }

        /// <summary>
        /// Gender property
        /// </summary>
        public Gender Gender { get; protected set; } 

        /// <summary>
        /// Validate personal identity number.
        /// </summary>
        /// <param name="errors">List of errors</param>
        /// <returns>True if personal identity number is ok.</returns>
        public bool Validate(out IList<string> errors)
        {
            errors = new List<string>();
            if (validations.Length < 1) return false;
            foreach (IPersonalIdentityNumberValidation validation in validations)
            {
                if (!validation.Validate())
                {
                    //FullName = validation class name with namespace
                    errors.Add(validation.GetType().FullName); 
                }
            }
            return errors.Count > 0 ? false : true;
        }

        /// <summary>
        /// Validate personal identity number.
        /// </summary>
        /// <returns>True if personal identity number is ok.</returns>
        public bool Validate()
        {
            if (validations.Length < 1) return false;
            foreach (IPersonalIdentityNumberValidation validation in validations)
            {
                if (!validation.Validate()) return false;
            }
            return true;
        }
    }
}